import competition
import round
from round import *
from option import Option

def addComp(self, prefix, title, subtitle):
	if title in Option().competitions:
		return self.message(prefix+'/error name_duplicate')

	Option().competitions[title]=competition.Competition(title,subtitle)

def addRound(self, prefix, competition, round):
	if not competition in Option().competitions:
		return self.transport.write('/error no_such_competition\n')

	Option().competitions[competition].addRound(round)

def start(self, prefix, competition):

	if not competition in Option().competitions:
		return self.transport.write('/error no_such_competition\n')

	if Option().actual_competition != None:
		return self.transport.write('/error competition_running_already\n')

	comp = Option().competitions[competition]

	if comp.actual_round == len(comp.rounds):
		return self.transport.write('/error competition_finished\n')

	Option().actual_competition = comp
	comp.start()

def evalfile(self, prefix, f):
	execfile(f)

def broadcast(msg):
	for u in Option().factoryChat.clients:
		u.message(msg)




